package com.clock.note;

import java.util.Calendar;

import com.slz.note.MainActivity;
import com.slz.note.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TimePicker;




//闹钟提醒

public class Clock_Remind extends Activity {

	private Button mSet;
	Calendar mCalendar = Calendar.getInstance();


	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_colck);
		ObjectPool.mAlarmHelper = new AlarmHelper(this);
		mSet = (Button) findViewById(R.id.mSet);
		setListener();
	}
//给按钮设置监听
	public void setListener() {
		mSet.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				mCalendar.setTimeInMillis(System.currentTimeMillis());
				int mHour = mCalendar.get(Calendar.HOUR_OF_DAY);
				int mMinute = mCalendar.get(Calendar.MINUTE);
				new TimePickerDialog(Clock_Remind.this,
						new TimePickerDialog.OnTimeSetListener() {
							public void onTimeSet(TimePicker view,
									int hourOfDay, int minute) {
								mCalendar.setTimeInMillis(System
										.currentTimeMillis());
								mCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
								mCalendar.set(Calendar.MINUTE, minute);
								mCalendar.set(Calendar.SECOND, 0);
								mCalendar.set(Calendar.MILLISECOND, 0);
								ObjectPool.mAlarmHelper.openAlarm(32, "ddd",
										"ffff", mCalendar.getTimeInMillis());
							}
						}, mHour, mMinute, true).show();
			}
		});
	}
	
	@Override
	//按返回键返回首页
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			//showBackDialog();
			Intent intent = new Intent(Clock_Remind.this,MainActivity.class);
			startActivity(intent);
			finish();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}
	


}
